/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.losalpes.compras;

import com.losalpes.carrito.CarritoServicesLocal;
import com.losalpes.persistence.entity.Articulo;
import com.losalpes.persistence.entity.Mueble;
import com.losalpes.security.SecurityBean;
import java.util.List;
import javax.ejb.EJB;

/**
 *
 * @author Oscar Ballesteros
 */
public class CarritoBean {

    @EJB
    private CarritoServicesLocal carritoServicesLocal;
    private SecurityBean securityBean;
    private PagarBean pagarBean;

    public CarritoBean() {        
    }

    public void agregarItemCarrito(Mueble mueble){
       carritoServicesLocal.agregarItemCarrito(mueble);
    }

    public void limpiarCarrito(){
        carritoServicesLocal.limpiarCarrito();
    }

    public Double getTotal() {
        return carritoServicesLocal.getTotalCarrito();
    }

    public String irComprar(){
        if(securityBean.getUsername() == null){
            return "login";
        }
        return "go_comprar";
    }

    public String armarCompra(){
        pagarBean.prepararCompra(carritoServicesLocal.getCarrito());
        return "go_pagar";
    }

    public List<Articulo> getCarrito() {
        return carritoServicesLocal.getCarrito();
    }

    public void setCarrito(List<Articulo> carrito)
    {
        for(Articulo art : carrito)
        {
            carritoServicesLocal.actualizarCantidadArticulo(art);
        }        
    }

    public void updateCantidad(Articulo art)
    {
        carritoServicesLocal.actualizarCantidadArticulo(art);
    }



    public SecurityBean getSecurityBean() {
        return securityBean;
    }

    public void setSecurityBean(SecurityBean securityBean) {
        this.securityBean = securityBean;
    }

    public PagarBean getPagarBean() {
        return pagarBean;
    }

    public void setPagarBean(PagarBean pagarBean) {
        this.pagarBean = pagarBean;
    }
    
}
